package com.example.util;


import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class ChineseMobileNumberGenerator {

    // 中国主要手机号段（最新）
    private static final List<String> MOBILE_PREFIXES = Arrays.asList(
            // 中国移动
            "134", "135", "136", "137", "138", "139",
            "147", "148", "150", "151", "152", "157",
            "158", "159", "172", "178", "182", "183",
            "184", "187", "188", "195", "197", "198",

            // 中国联通
            "130", "131", "132", "140", "145", "146",
            "155", "156", "166", "167", "171", "175",
            "176", "185", "186", "196",

            // 中国电信
            "133", "1349", "141", "149", "153", "162",
            "173", "174", "177", "180", "181", "189",
            "190", "191", "193", "199",

            // 虚拟运营商
            "165", "167", "170"
    );

    private static final Random RANDOM = ThreadLocalRandom.current();

    /**
     * 生成一个随机的中国手机号
     * @return 11位手机号字符串
     */
    public static String generate() {
        // 1. 随机选择一个号段
        String prefix = MOBILE_PREFIXES.get(RANDOM.nextInt(MOBILE_PREFIXES.size()));

        // 2. 生成剩余的数字
        int remainingLength = 11 - prefix.length();
        StringBuilder number = new StringBuilder(prefix);

        for (int i = 0; i < remainingLength; i++) {
            number.append(RANDOM.nextInt(10));
        }

        return number.toString();
    }

    /**
     * 批量生成手机号
     * @param count 生成数量
     * @return 手机号列表
     */
    public static List<String> generateBatch(int count) {
        return IntStream.range(0, count)
                .mapToObj(i -> generate())
                .collect(Collectors.toList());
    }

    public static void main(String[] args) {
        // 生成单个手机号
        System.out.println("单个手机号: " + generate());
    }
}
